package org.yihang.annotation.easyui;

import org.yihang.annotation.FindByVo;

import static org.yihang.util.MapperGenerator.firstUpper;

import java.lang.reflect.Field;

public enum SearchType {
	BetweenDate {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			String m1 = "min" + firstUpper(f.getName());
			String m2 = "max" + firstUpper(f.getName());
			return ui.label() + " 从: <input class=\"easyui-datebox\" name=\"" + m1 + "\" style=\"width:" + ui.width()
					+ "px\"> 到: <input class=\"easyui-datebox\" name=\"" + m2 + "\" style=\"width:" + ui.width()
					+ "px\">";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "";
		}
	},
	BetweenDateTime {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			String m1 = "min" + firstUpper(f.getName());
			String m2 = "max" + firstUpper(f.getName());
			return ui.label() + " 从: <input class=\"easyui-datetimebox\" name=\"" + m1 + "\" style=\"width:"
					+ ui.width() + "px\"> 到: <input class=\"easyui-datetimebox\" name=\"" + m2 + "\" style=\"width:"
					+ ui.width() + "px\">";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "";
		}
	},
	Combo {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			return ui.label() + " : <select id=\"" + classShortName + "_search_" + f.getName() + "\" name=\""
					+ f.getName() + "\" data-options=\"valueField:'" + ui.valueField() + "',textField:'"
					+ ui.textField() + "',panelHeight:'auto'\" style=\"width:" + ui.width() + "px\"></select>";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "$(\"#" + classShortName + "_search_" + f.getName() + "\").combobox({data:" + ui.source() + ",editable:false});";
		}
	},
	ComboMulti {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			return ui.label() + " : <select id=\"" + classShortName + "_search_" + f.getName() + "\" name=\""
					+ f.getName() + "\" data-options=\"valueField:'" + ui.valueField() + "',textField:'"
					+ ui.textField() + "',multiple:true,panelHeight:'auto'\" style=\"width:" + ui.width() + "px\"></select>";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "$(\"#" + classShortName + "_search_" + f.getName() + "\").combobox({data:" + ui.source() + ",editable:false});";
		}
	},
	ComboTree {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			return ui.label() + " : <select id=\"" + classShortName + "_search_" + f.getName() + "\" name=\""
					+ f.getName() + "\" data-options=\"panelHeight:'auto'\" style=\"width:" + ui.width() + "px\"></select>";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "$(\"#" + classShortName + "_search_" + f.getName() + "\").combotree({data:" + ui.source() + ",editable:false});";
		}
	},
	ComboTreeMulti {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			return ui.label() + " : <select id=\"" + classShortName + "_search_" + f.getName() + "\" name=\""
					+ f.getName() + "\" data-options=\"multiple:true,panelHeight:'auto'\" style=\"width:" + ui.width() + "px\"></select>";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "$(\"#" + classShortName + "_search_" + f.getName() + "\").combotree({data:" + ui.source() + ",editable:false});";
		}
	},
	Text {
		@Override
		public String html(String classShortName, Field f, Search ui, FindByVo vo) {
			return ui.label() + " : <input class=\"easyui-textbox\" name=\"" + f.getName() + "\" style=\"width:"
					+ ui.width() + "px\">";
		}

		@Override
		public String func(String classShortName, Field f, Search ui, FindByVo vo) {
			return "";
		}
	};

	public abstract String html(String classShortName, Field f, Search ui, FindByVo vo);

	public abstract String func(String classShortName, Field f, Search ui, FindByVo vo);
}
